﻿using Entity.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Entity
{
    public class DBContext : DbContext
    {
        protected DBContext()
        {
        }
        public DBContext(DbContextOptions options) : base(options)
        {
        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
        }

        public DbSet<MeterInfo> meterInfos { get; set; }
        public DbSet<RTUInfo> rTUInfos { get; set; }
        public DbSet<RechargeInfo> rechargeInfos { get; set; }
        public DbSet<LoginUserInfo> loginUserInfos { get; set; }
        public DbSet<RealDataInfo> realDataInfos { get; set; }

        public DbSet<ValveOperateInfo> valveOperateInfos { get; set; }
    }

    public class BaseContext
    {
        static string defaultConn = "Server=114.55.174.195;port=3306;Database=HuaRunMiddleDB;Uid=admin;Pwd=GZyb2021@#1;Character Set=utf8;";
        public static DBContext CreateContext(string connString = "")
        {
            if (connString == null)
            {
                connString = defaultConn;
            }
            var optionBuilder = new DbContextOptionsBuilder<DBContext>();

            optionBuilder.UseMySql(connString, ServerVersion.AutoDetect(connString)).UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
            optionBuilder.EnableSensitiveDataLogging();
            var context = new DBContext(optionBuilder.Options);
            return context;
        }
    }
}
